﻿using System.ServiceModel;
using System.ServiceModel.Channels;
using Crowler.Model.CoreComponents;

namespace CoreComponents
{
    public class ParentServiceProvider : IParentServiceProvider
    {
        private readonly IAppEnvironment _appEnv;

        public ParentServiceProvider(IAppEnvironment appEnvironment)
        {
            _appEnv = appEnvironment;
        }

        public T CreateParentService<T>(T parentServiceType, Binding binding, EndpointAddress endPoint) where T : class
        {
           return new WcfServiceWrapper<T>(binding, endPoint).Channel;
        }

        public T CreateParentService<T>(T parentServiceType)
        {
            return _appEnv.Resolve<T>();
        }
    }
}
